var app = getApp()
Page({
  data: {
    agentId:'',
    addressList:[]
  },
  onLoad: function (options) {
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId
      })
      this.getAddressList(res.data.agentId)
    })

  },
  onShow(){
    app.getMemInfo().then(res=>{
      this.setData({
        agentId:res.data.agentId
      })
      this.getAddressList(res.data.agentId)
    })
  },
  getAddressList(agentId){
    let data = {
      agentId
    }
    app.request('wx_app/agent/address/list',data,'GET').then(res=>{
      console.log(res)
      this.setData({
        addressList:res.data
      })
    })
  },
  editAddress(){
    wx.navigateTo({
      url:'../set/myAddress/myAddress?type=1'
    })
  },
  addAddress(){
    wx.navigateTo({
      url:'../myFactory/editMyFactory'
    })
  },
  getAddress(e){
    let info = e.currentTarget.dataset.info
    console.log(info)
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    prevPage.setData({
      ['goodsList[0].name']:info.contactName,
      ['goodsList[0].phone']:info.mobilePhone,
      ['goodsList[0].address']:info.provinceName==info.cityName?''+info.cityName+info.countryName+info.address:info.provinceName+info.cityName+info.countryName+info.address,
      ['goodsList[0].agentAddressId']:info.id
    })
    wx.navigateBack()
  }
})





























